package 并发编程源码;

import java.util.concurrent.locks.ReentrantLock;

/**
 * TODO
 *
 * @Description
 * @Author Lx
 * @Date 2024/5/28 14:48
 **/


public class Count {
    volatile int count;
    ReentrantLock reentrantLock=new ReentrantLock();
    public Count(int count){
        this.count=count;
    }

    public void add(){
        reentrantLock.lock();
        try{
            count+=1;
            Thread.sleep(5L);//休眠5ms
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            reentrantLock.unlock();
        }
    }

    public int getCount(){
        return this.count;
    }
}
